package com.wangxiaonan.wxwork.config;

import org.quartz.Scheduler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * @Author: wangxiaonan
 * @Date: 2018/8/29
 **/
@Configuration
public class QuartzConfig {
    public static final String APPLICATION_CONTEXT_KEY = "applicationContext";

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        schedulerFactoryBean.setApplicationContextSchedulerContextKey(APPLICATION_CONTEXT_KEY);
        return schedulerFactoryBean;
    }

    @Bean
    @Order
    public Scheduler scheduler(SchedulerFactoryBean schedulerFactoryBean) {
        return schedulerFactoryBean.getScheduler();
    }
}
